package com.ingenic.glass.camera.pqylive;

import android.content.Context;
import android.util.Log;
import cn.ingenic.glasssync.services.SyncData;
import cn.ingenic.glasssync.services.SyncException;
import cn.ingenic.glasssync.services.SyncModule;

public class PqyLiveModule extends SyncModule {

        private static final String TAG = "PqyLiveModule";
        private static PqyLiveModule mInstance = null;
        private Context mContext = null;

        public static final String KEY_TYPE = "type";
        public static final String KEY_LIVESTATUS = "status";

        public static final int TYPE_PQYLIVE = 0;
        public static final int TYPE_LIVESTATUS = 1;

        public static PqyLiveModule getInstance (Context context) {
                if (null == mInstance) {
                        mInstance = new PqyLiveModule("PqyLiveModule", context);
                }
                return mInstance;
        }

        private PqyLiveModule(String name, Context context) {
                super(name, context);
                mContext = context;
        }

        @Override
        protected void onCreate() {
        }

        @Override
        protected void onRetrive(SyncData data) {
                int type = data.getInt(KEY_TYPE);
                switch (type) {
                case TYPE_PQYLIVE: {
                        Log.d(TAG, "TYPE_PQYLIVE");
                        new PqyLiveBroadcastReceiver().live(mContext);
                }
                break;
                case TYPE_LIVESTATUS: {
                        SyncData syncData = new SyncData();
                        syncData.putInt("type", PqyLiveModule.TYPE_LIVESTATUS);
                        syncData.putString(PqyLiveModule.KEY_LIVESTATUS, PqyLiveBroadcastReceiver.getCurrentLiveStatus());
                        try {
                                send(syncData);
                        } catch (SyncException e) {
                                e.printStackTrace();
                        }
                }
                break;
                default: {
                        Log.w(TAG, "Unknown type: " + type);
                }
                break;
                }
        }

}
